package annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * 校验字段值是否在指定的范围内
 *
 * @author zhanglinfeng
 * @date create in 2024/10/11 11:17
 */
public class FlagValidatorClass implements ConstraintValidator<FlagValidator, Object> {
    private String[] values;

    @Override
    public void initialize(FlagValidator flagValidator) {
        this.values = flagValidator.value();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
        return Arrays.stream(values).allMatch(t -> t.equals(String.valueOf(value)));
    }
}
